home *** CD-ROM | disk | FTP | other *** search
/ Programming in Microsoft Windows with C# / Programacion en Microsoft Windows con C#.iso / Original Code / Font Fun / HollowFont / HollowFont.cs next >
Encoding:
Text File  |  2001-01-15  |  1.2 KB  |  42 lines

  1. //-----------------------------------------
  2. // HollowFont.cs ⌐ 2001 by Charles Petzold
  3. //-----------------------------------------
  4. using System;
  5. using System.Drawing;
  6. using System.Drawing.Drawing2D;
  7. using System.Windows.Forms;
  8.  
  9. class HollowFont: FontMenuForm
  10. {
  11.      public new static void Main()
  12.      {
  13.           Application.Run(new HollowFont());
  14.      }
  15.      public HollowFont()
  16.      {
  17.           Text = "Hollow Font";
  18.           Width *= 2; 
  19.           strText = "Hollow";
  20.           font = new Font("Times New Roman", 108);
  21.      }
  22.      protected override void DoPage(Graphics grfx, Color clr, int cx, int cy)
  23.      {
  24.           GraphicsPath path = new GraphicsPath();
  25.           float fFontSize = PointsToPageUnits(grfx, font);
  26.  
  27.                // Get coordinates for a centered string.
  28.  
  29.           SizeF sizef = grfx.MeasureString(strText, font);
  30.           PointF ptf = new PointF((cx - sizef.Width) / 2, 
  31.                                   (cy - sizef.Height) / 2);
  32.  
  33.                // Add text to the path.
  34.  
  35.           path.AddString(strText, font.FontFamily, (int) font.Style,
  36.                          fFontSize, ptf, new StringFormat());
  37.  
  38.                // Draw the path.
  39.  
  40.           grfx.DrawPath(new Pen(clr), path);
  41.      }
  42. }